package com.lagou.web.framework.annotation.listener;

import com.lagou.web.framework.annotation.factory.BeanFactory;
import com.lagou.web.framework.annotation.factory.SingletonBeanFactory;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

public class ContextLoaderListener implements ServletContextListener {

    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {
        String contextConfig = servletContextEvent.getServletContext().getInitParameter("contextConfig");
        if (contextConfig != null) {
            BeanFactory.setSingletonMap(new SingletonBeanFactory().initSingletonMap(contextConfig));
        }
    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {
    }
}
